package com.mshopping.app.manager;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

import android.app.Activity;

/**
 * This class is used for acivity 程序栈
 * 
 * @author liuhuan
 * @version 1.0, 2013-8-31 下午11:02:16
 */
public class ActivityTask {
	private static Map<String, Activity> activitiesTask = null;
	private static ActivityTask instance = null;

	private ActivityTask() {
		activitiesTask = Collections.synchronizedMap(new LinkedHashMap<String, Activity>());
	}

	public static ActivityTask getInstance() {
		if (instance == null) {
			instance = new ActivityTask();
		}
		return instance;
	}

	public Activity getActivity(String key) {
		if (activitiesTask.containsKey(key)) {
			return activitiesTask.get(key);
		}
		return null;
	}

	public void put(String key, Activity value) {
		if (activitiesTask.containsKey(key)) {
			activitiesTask.remove(key);
		}
		activitiesTask.put(key, value);
	}

	public void remove(String key) {
		activitiesTask.remove(key);
	}

	public void finishAllActivity() {
		for (String key : activitiesTask.keySet()) {
			Activity activity = activitiesTask.get(key);
			if (activity != null) {
				activity.finish();
			}
		}
	}
}
